<?php

namespace Open\Pages;

/**
 * Description of Page
 *
 * @author nofear
 */
class Page extends \Shared\Page {

    protected $product = 'Page';

    /**
     * @var \Shared\LRC\LRCSupport
     */
    protected $LRCSupport;

    public function __construct() {
        parent::__construct();

        $this->LRCSupport = \Shared\Application::getInstance()->getLRCSupport();
    }

    protected function getCurrentPage($key) {
        $QB      = $this->EntityManager->createQueryBuilder();
        $LRCPage = $QB->select('p')
                        ->from('Shared\Main\LRC\Page', 'p')
                        ->andWhere('p.Language = :Language')
                        ->andWhere('p.slug = :key')
                        ->setParameter('Language', $this->LRCSupport->getCurrentLanguage())
                        ->setParameter('key', $key)
                        ->setMaxResults(1)
                        ->getQuery()->getOneOrNullResult();
        
        if (!$LRCPage) {
            throw new \Shared\Exceptions\NotFoundException('Page not found', 404);
        }

        return $LRCPage->getObject();
    }

}
